import { Directive, ElementRef, HostListener } from '@angular/core';

@Directive({
  selector: '[appInputToInt]'
})
export class InputToIntDirective {

  constructor(private el: ElementRef) { }
  @HostListener("keyup") toInt() {
    if(this.el.nativeElement instanceof HTMLInputElement){
      this.el.nativeElement.value = this.el.nativeElement.value.replace(/[^0-9]+/g, '')
    }else{
      throw(`appInputToInt can't directive ${this.el.nativeElement.type} instead of Input Element`)
    }
  }

}
